From 187a0366b6643f7eca4e7121012f4e8bfd231e70 Mon Sep 17 00:00:00 2001 From: "kaf24@freefall.cl.cam.ac.uk" Date: Sun, 31 Oct 2004 08:17:49 +0000 Subject: [PATCH] bitkeeper revision 1.1159.142.2 (41849fadYlUYMwSy6tcq8Y-Yi8NMZA) Clean up libxc by allowing direct use of Xen headers from userland: #include --- BitKeeper/etc/ignore | 1 + tools/libxc/Makefile | 12 ++++---- tools/libxc/xc.h | 56 ++++++++++++------------------------- tools/libxc/xc_domain.c | 19 ++++++++----- tools/libxc/xc_evtchn.c | 16 +---------- tools/libxc/xc_linux_save.c | 43 ++++++++++++++-------------- tools/libxc/xc_misc.c | 10 ++----- tools/libxc/xc_private.h | 14 ---------- tools/misc/Makefile | 1 - tools/xentrace/Makefile | 1 - tools/xentrace/xentrace.c | 4 +-- tools/xfrd/Makefile | 3 -- xen/Makefile | 4 +++ 13 files changed, 67 insertions(+), 117 deletions(-) diff --git a/BitKeeper/etc/ignore b/BitKeeper/etc/ignore index d039d56f50..607dc5adf5 100644 --- a/BitKeeper/etc/ignore +++ b/BitKeeper/etc/ignore @@ -32,6 +32,7 @@ patches/* tools/*/build/lib*/*.py tools/balloon/balloon tools/check/.* +tools/libxc/xen tools/misc/miniterm/miniterm tools/misc/xen_cpuperf tools/web-shutdown.tap diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index 1678a1a448..18c09c2f6c 100644 --- a/tools/libxc/Makefile +++ b/tools/libxc/Makefile @@ -8,9 +8,6 @@ CC = gcc XEN_ROOT = ../.. include $(XEN_ROOT)/tools/Make.defs -vpath %.h $(XEN_HYPERVISOR_IFS) -INCLUDES += -I $(XEN_HYPERVISOR_IFS) - vpath %h $(XEN_LINUX_INCLUDE) INCLUDES += -I $(XEN_LINUX_INCLUDE) @@ -44,7 +41,7 @@ OBJS = $(patsubst %.c,%.o,$(SRCS)) LIB = libxc.so libxc.so.$(MAJOR) libxc.so.$(MAJOR).$(MINOR) -all: check-for-zlib $(LIB) +all: check-for-zlib mk-symlinks $(LIB) check-for-zlib: @if [ ! -e /usr/include/zlib.h ]; then \ @@ -54,6 +51,9 @@ check-for-zlib: false; \ fi +mk-symlinks: + ln -sf $(XEN_HYPERVISOR_IFS) xen + install: all mkdir -p $(prefix)/usr/lib mkdir -p $(prefix)/usr/include @@ -61,9 +61,7 @@ install: all install -m0644 xc.h $(prefix)/usr/include clean: - $(RM) *.a *.so *.o *.rpm $(LIB) - $(RM) *~ - $(RM) $(DEPS) + $(RM) *.a *.so *.o *.rpm $(LIB) *~ $(DEPS) xen rpm: all rm -rf staging diff --git a/tools/libxc/xc.h b/tools/libxc/xc.h index 027d76711f..4f01a8d9b4 100644 --- a/tools/libxc/xc.h +++ b/tools/libxc/xc.h @@ -3,7 +3,7 @@ * * A library for low-level access to the Xen control interfaces. * - * Copyright (c) 2003, K A Fraser. + * Copyright (c) 2003-2004, K A Fraser. */ #ifndef __XC_H__ @@ -18,6 +18,12 @@ typedef signed short s16; typedef signed long s32; typedef signed long long s64; +#include "xen/hypervisor-if.h" +#include "xen/dom0_ops.h" +#include "xen/event_channel.h" +#include "xen/sched_ctl.h" +#include "xen/io/domain_controller.h" + /* Obtain or relinquish a handle on the 'xc' library. */ int xc_interface_open(void); int xc_interface_close(int xc_handle); @@ -34,14 +40,7 @@ typedef struct { unsigned long max_memkb; } xc_dominfo_t; -typedef struct xc_shadow_control_stats_st -{ - unsigned long fault_count; - unsigned long dirty_count; - unsigned long dirty_net_count; - unsigned long dirty_block_count; -} xc_shadow_control_stats_t; - +typedef dom0_getdomaininfo_t xc_domaininfo_t; int xc_domain_create(int xc_handle, unsigned int mem_kb, int cpu, @@ -60,10 +59,18 @@ int xc_domain_getinfo(int xc_handle, u32 first_domid, unsigned int max_doms, xc_dominfo_t *info); +int xc_domain_getfullinfo(int xc_handle, + u32 domid, + xc_domaininfo_t *info, + full_execution_context_t *ctxt); int xc_domain_setcpuweight(int xc_handle, u32 domid, float weight); +long long xc_domain_get_cpu_usage(int xc_handle, + domid_t domid); + +typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t; int xc_shadow_control(int xc_handle, u32 domid, unsigned int sop, @@ -125,27 +132,7 @@ int xc_rrobin_global_set(int xc_handle, u64 slice); int xc_rrobin_global_get(int xc_handle, u64 *slice); -#define DOMID_SELF (0x7FF0U) -#define DOMID_IO (0x7FF1U) -#define DOMID_XEN (0x7FF2U) - -typedef struct { -#define EVTCHNSTAT_closed 0 /* Chennel is not in use. */ -#define EVTCHNSTAT_unbound 1 /* Channel is not bound to a source. */ -#define EVTCHNSTAT_interdomain 2 /* Channel is connected to remote domain. */ -#define EVTCHNSTAT_pirq 3 /* Channel is bound to a phys IRQ line. */ -#define EVTCHNSTAT_virq 4 /* Channel is bound to a virtual IRQ line */ - int status; - union { - struct { - u32 dom; - int port; - } interdomain; - int pirq; - int virq; - } u; -} xc_evtchn_status_t; - +typedef evtchn_status_t xc_evtchn_status_t; int xc_evtchn_alloc_unbound(int xc_handle, u32 dom, int *port); @@ -179,14 +166,7 @@ int xc_readconsolering(int xc_handle, unsigned int max_chars, int clear); -typedef struct { - int ht_per_core; - int cores; - unsigned long total_pages; - unsigned long free_pages; - unsigned long cpu_khz; -} xc_physinfo_t; - +typedef dom0_physinfo_t xc_physinfo_t; int xc_physinfo(int xc_handle, xc_physinfo_t *info); diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 958d85a69e..67168910e9 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -120,16 +120,21 @@ int xc_domain_getinfo(int xc_handle, int xc_domain_getfullinfo(int xc_handle, u32 domid, - dom0_op_t *op, - full_execution_context_t *ctxt ) + xc_domaininfo_t *info, + full_execution_context_t *ctxt) { int rc; - op->cmd = DOM0_GETDOMAININFO; - op->u.getdomaininfo.domain = (domid_t)domid; - op->u.getdomaininfo.ctxt = ctxt; + dom0_op_t op; + + op.cmd = DOM0_GETDOMAININFO; + op.u.getdomaininfo.domain = (domid_t)domid; + op.u.getdomaininfo.ctxt = ctxt; + + rc = do_dom0_op(xc_handle, &op); + + memcpy(info, &op.u.getdomaininfo, sizeof(*info)); - rc = do_dom0_op(xc_handle, op); - if ( ((u16)op->u.getdomaininfo.domain != domid) && rc > 0 ) + if ( ((u16)op.u.getdomaininfo.domain != domid) && rc > 0 ) return -ESRCH; else return rc; diff --git a/tools/libxc/xc_evtchn.c b/tools/libxc/xc_evtchn.c index 2f78ef7936..9371e61261 100644 --- a/tools/libxc/xc_evtchn.c +++ b/tools/libxc/xc_evtchn.c @@ -134,21 +134,7 @@ int xc_evtchn_status(int xc_handle, op.u.status.port = port; if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 ) - { - switch ( status->status = op.u.status.status ) - { - case EVTCHNSTAT_interdomain: - status->u.interdomain.dom = (u16)op.u.status.u.interdomain.dom; - status->u.interdomain.port = op.u.status.u.interdomain.port; - break; - case EVTCHNSTAT_pirq: - status->u.pirq = op.u.status.u.pirq; - break; - case EVTCHNSTAT_virq: - status->u.virq = op.u.status.u.virq; - break; - } - } + memcpy(status, &op.u.status, sizeof(*status)); return rc; } diff --git a/tools/libxc/xc_linux_save.c b/tools/libxc/xc_linux_save.c index 7e0ab5c502..e9f4259494 100644 --- a/tools/libxc/xc_linux_save.c +++ b/tools/libxc/xc_linux_save.c @@ -319,9 +319,9 @@ static int analysis_phase( int xc_handle, u32 domid, } -int suspend_and_state( int xc_handle, XcIOContext *ioctxt, - dom0_op_t *op, - full_execution_context_t *ctxt ) +int suspend_and_state(int xc_handle, XcIOContext *ioctxt, + xc_domaininfo_t *info, + full_execution_context_t *ctxt) { int i=0; @@ -329,26 +329,26 @@ int suspend_and_state( int xc_handle, XcIOContext *ioctxt, retry: - if ( xc_domain_getfullinfo( xc_handle, ioctxt->domain, op, ctxt) ) + if ( xc_domain_getfullinfo(xc_handle, ioctxt->domain, info, ctxt) ) { xcio_error(ioctxt, "Could not get full domain info"); return -1; } - if ( (op->u.getdomaininfo.flags & - ( DOMFLAGS_SHUTDOWN | (SHUTDOWN_suspend<flags & + (DOMFLAGS_SHUTDOWN | (SHUTDOWN_suspend<u.getdomaininfo.flags & DOMFLAGS_PAUSED ) + if ( info->flags & DOMFLAGS_PAUSED ) { // try unpausing domain, wait, and retest xc_domain_unpause( xc_handle, ioctxt->domain ); xcio_error(ioctxt, "Domain was paused. Wait and re-test. (%lx)", - op->u.getdomaininfo.flags); + info->flags); usleep(10000); // 10ms goto retry; @@ -358,20 +358,21 @@ retry: if( ++i < 100 ) { xcio_error(ioctxt, "Retry suspend domain (%lx)", - op->u.getdomaininfo.flags); + info->flags); usleep(10000); // 10ms goto retry; } xcio_error(ioctxt, "Unable to suspend domain. (%lx)", - op->u.getdomaininfo.flags); + info->flags); return -1; } int xc_linux_save(int xc_handle, XcIOContext *ioctxt) { - dom0_op_t op; + xc_domaininfo_t info; + int rc = 1, i, j, k, last_iter, iter = 0; unsigned long mfn; u32 domid = ioctxt->domain; @@ -441,12 +442,12 @@ int xc_linux_save(int xc_handle, XcIOContext *ioctxt) return 1; } - if ( xc_domain_getfullinfo( xc_handle, domid, &op, &ctxt) ) + if ( xc_domain_getfullinfo( xc_handle, domid, &info, &ctxt) ) { xcio_error(ioctxt, "Could not get full domain info"); goto out; } - shared_info_frame = op.u.getdomaininfo.shared_info_frame; + shared_info_frame = info.shared_info_frame; /* A cheesy test to see whether the domain contains valid state. */ if ( ctxt.pt_base == 0 ){ @@ -454,7 +455,7 @@ int xc_linux_save(int xc_handle, XcIOContext *ioctxt) goto out; } - nr_pfns = op.u.getdomaininfo.max_pages; + nr_pfns = info.max_pages; /* cheesy sanity check */ if ( nr_pfns > 1024*1024 ){ @@ -536,10 +537,10 @@ int xc_linux_save(int xc_handle, XcIOContext *ioctxt) last_iter = 1; - if ( suspend_and_state( xc_handle, ioctxt, &op, &ctxt) ) + if ( suspend_and_state( xc_handle, ioctxt, &info, &ctxt) ) { xcio_error(ioctxt, "Domain appears not to have suspended: %lx", - op.u.getdomaininfo.flags); + info.flags); goto out; } @@ -900,17 +901,17 @@ int xc_linux_save(int xc_handle, XcIOContext *ioctxt) DPRINTF("Start last iteration\n"); last_iter = 1; - if ( suspend_and_state( xc_handle, ioctxt, &op, &ctxt) ) + if ( suspend_and_state( xc_handle, ioctxt, &info, &ctxt) ) { xcio_error(ioctxt, "Domain appears not to have suspended: %lx", - op.u.getdomaininfo.flags); + info.flags); goto out; } xcio_info(ioctxt, "SUSPEND flags %08lx shinfo %08lx eip %08lx " - "esi %08lx\n", op.u.getdomaininfo.flags, - op.u.getdomaininfo.shared_info_frame, + "esi %08lx\n",info.flags, + info.shared_info_frame, ctxt.cpu_ctxt.eip, ctxt.cpu_ctxt.esi ); } diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c index 0019ffe96b..e8ea18c5ff 100644 --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -52,18 +52,14 @@ int xc_physinfo(int xc_handle, { int ret; dom0_op_t op; - dom0_physinfo_t *got_info = &op.u.physinfo; op.cmd = DOM0_PHYSINFO; op.interface_version = DOM0_INTERFACE_VERSION; - if((ret = do_dom0_op(xc_handle, &op))) return ret; + if ( (ret = do_dom0_op(xc_handle, &op)) != 0 ) + return ret; - put_info->ht_per_core = got_info->ht_per_core; - put_info->cores = got_info->cores; - put_info->total_pages = got_info->total_pages; - put_info->free_pages = got_info->free_pages; - put_info->cpu_khz = got_info->cpu_khz; + memcpy(put_info, &op.u.physinfo, sizeof(*put_info)); return 0; } diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h index 3da14a16a8..8fd4559886 100644 --- a/tools/libxc/xc_private.h +++ b/tools/libxc/xc_private.h @@ -16,13 +16,6 @@ #include "xc.h" -/* from xen/include/hypervisor-ifs */ -#include -#include -#include -#include -#include - #include @@ -193,15 +186,8 @@ typedef struct mfn_mapper { } mfn_mapper_t; -long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid ); - #include "xc_io.h" -int xc_domain_getfullinfo(int xc_handle, - u32 domid, - dom0_op_t *op, - full_execution_context_t *ctxt ); - unsigned long xc_get_m2p_start_mfn ( int xc_handle ); #endif /* __XC_PRIVATE_H__ */ diff --git a/tools/misc/Makefile b/tools/misc/Makefile index 741f32976c..0dc13c4b50 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -5,7 +5,6 @@ include $(XEN_ROOT)/tools/Make.defs CC = gcc CFLAGS = -Wall -O3 -INCLUDES += -I $(XEN_HYPERVISOR_IFS) INCLUDES += -I $(XEN_LINUX_INCLUDE) INCLUDES += -I $(XEN_XC) INCLUDES += -I $(XEN_LIBXC) diff --git a/tools/xentrace/Makefile b/tools/xentrace/Makefile index de5350e3c2..7759b90f86 100644 --- a/tools/xentrace/Makefile +++ b/tools/xentrace/Makefile @@ -5,7 +5,6 @@ include $(XEN_ROOT)/tools/Make.defs CC = gcc CFLAGS = -Wall -Werror -O3 -CFLAGS += -I $(XEN_HYPERVISOR_IFS) CFLAGS += -I $(XEN_LINUX_INCLUDE) CFLAGS += -I $(XEN_XC) CFLAGS += -I $(XEN_LIBXC) diff --git a/tools/xentrace/xentrace.c b/tools/xentrace/xentrace.c index 2df1ed9462..351ecd71a8 100644 --- a/tools/xentrace/xentrace.c +++ b/tools/xentrace/xentrace.c @@ -22,9 +22,7 @@ #include #include "xc_private.h" - -/* from xen/include/hypervisor-ifs */ -#include +#include extern FILE *stderr; diff --git a/tools/xfrd/Makefile b/tools/xfrd/Makefile index 5824960ac9..9b8d9bc108 100644 --- a/tools/xfrd/Makefile +++ b/tools/xfrd/Makefile @@ -9,9 +9,6 @@ include $(XEN_ROOT)/tools/Make.defs XFRD_INSTALL_DIR = /usr/sbin -vpath %.h $(XEN_HYPERVISOR_IFS) -INCLUDES += -I $(XEN_HYPERVISOR_IFS) - vpath %h $(XEN_LINUX_INCLUDE) INCLUDES += -I $(XEN_LINUX_INCLUDE) diff --git a/xen/Makefile b/xen/Makefile index deda917692..ae43aa188c 100644 --- a/xen/Makefile +++ b/xen/Makefile @@ -22,6 +22,10 @@ install: $(TARGET) mkdir -p $(prefix)/boot install -m0644 $(TARGET).gz $(prefix)/boot install -m0644 $(TARGET)-syms $(prefix)/boot + mkdir -p $(prefix)/usr/include/xen/io + install -m0644 include/hypervisor-ifs/*.h $(prefix)/usr/include/xen + install -m0644 include/hypervisor-ifs/io/*.h $(prefix)/usr/include/xen/io + install -m0644 include/hypervisor-ifs/COPYING $(prefix)/usr/include/xen dist: $(TARGET) $(MAKE) prefix=`pwd`/../install dist=yes install -- 2.30.2